### Alizade, Dancygier, Ditlmann
### "National Penalties Reversed"
### Replication Code 
### Figure A1
### For questions, contact jalizade@princeton.edu

# setup
rm(list = ls())
setwd("C:/Users/Jey/Dropbox/WZB/NaturalizationExperiment/Submission/JOP/replication_JOP/data")
options(java.parameters = "-Xmx8000m")
library(foreign)
library(rgdal)
library(rgeos)
library(maptools)
library(ggplot2)
library(dplyr)

# load shapfile of Germany
shape <- readOGR(".", "VG250_GEM")

# load file with all municipalities with a population >= 2000
muns <- read.dta("data_munic_2000+.dta")

# subset columns
email <- muns[,c("ags", "email_address")]

# combine with shapefile
fort <- fortify(shape, region = "AGS")
fort <- left_join(fort, email, by = c("id" = "ags"))

# categorize in YES, NO, and population < 2000 (which are not relevant for us)
fort$cat[fort$email == 1] <- "Yes"
fort$cat[fort$email == 0] <- "No"
fort$cat[is.na(fort$email)] <- "Population < 2000"
fort$cat <- factor(fort$cat, levels = c("No", "Yes", "Population < 2000"))

# create map
map <- ggplot()
map <- map + geom_polygon(data = fort, aes(x = long, y = lat, group = group, fill = factor(cat)),
                          size = 0.2, color = "black")
map <- map + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
                   axis.title = element_blank(),
                   axis.text = element_blank(),
                   axis.ticks = element_blank(),
                   legend.title = element_text(size = 10, face = "bold"),
                   legend.position = "bottom",
                   panel.border = element_blank(),
                   panel.background = element_blank())
map <- map + guides(fill = guide_legend(title.position = "top"))
map <- map + scale_fill_manual(values = c("darkgreen", "red", "grey"),
                               name = "Email Addresses on Local Council Website")




